<template>
    <div>
        <path-tracking :path="path"/> 
        <div class="formLayout">
            <el-row class="rows basic">
                <el-col :sm="12" :md="8" :lg="6">
                    <div class="items">
                        <label class="label" for="">
                            <img class="required" src="@/assets/img/flower_red.png" alt="">
                            客户类型
                        </label>
                        <el-select size="small" class="input-cont" placeholder="请选择内容" v-model="customerClassify">
                            <el-option label="已成交客户" :value="1"></el-option>
                            <el-option label="未成交客户" :value="0"></el-option>
                        </el-select>
                    </div>
                </el-col>
            </el-row>
            <el-row class="rows basic" style="margin-top: 1rem;">
                <el-col>
                    <div class="items">
                        <label class="label" for="">
                            事项内容
                        </label>
                        <el-input type='textarea' rows="10" class="textArea" v-model="content" />
                    </div>
                </el-col>
            </el-row>
            <div class="formBtnList">
                <button class="sureBtn" @click="toSure">确定</button>
                <button class="cancelBtn" @click="toCancel">取消</button>
            </div>
        </div>
        
    </div>
</template>

<script>
import pathTracking from '@/components/common/pathTracking'
export default {
    name:'editMatter',
    components:{
        pathTracking,
    },
    data(){
        return{
            path: ['CRM', '营销宝典', {label: '注意事项', name: 'attentionMatter'}, '编辑'],
            customerClassify:'',
            content:'',
            id:''
        }
    },
    methods:{
        toCancel(){
            this.$router.replace({name:'attentionMatter'})
        },
        getEditInfo(id){
            var that = this;
            that.$ajax({
				url:api.crm + '/noticesInfo/'+id,
				method:'GET',
			}).then((res) => {
                //console.log('获取编辑信息',res);
                var data = res.data;
                if(data.status == 200){
                    var editInfo = data.result;
                    if(editInfo.customerClassify == 1){
                        editInfo.customerClassify = 1
                    }else{
                        editInfo.customerClassify = 0
                    }
                    that.customerClassify = editInfo.customerClassify;
                    that.content = editInfo.content
                }else{
                    // that.$message({
                    //     message: '获取编辑数据失败',
                    //     type: 'warning'
                    // });
                }
            }).catch((err) =>{
                that.$message({
                    message: err.data.msg,
                    type: 'warning'
                });
            })
        },
        toSure(){
            var that = this;
            var obj = {
                customerClassify:this.customerClassify,
                content:this.content,
                id:this.id
            }
			that.$ajax({
				url:api.crm + '/noticesInfo',
				method:'PUT',
				data:obj
			}).then((res) => {
                var data = res.data;
                if(data.status == 200){
                    that.$message({
                        message: '编辑事项成功',
                        type: 'success'
                    });
                    setTimeout(function(){
                        //that.clearData();
                        that.toJump()
                    },2000)
                }else{
                    that.$message({
                        message: data.msg,
                        type: 'warning'
                    });
                }
            }).catch((err) => {
                that.$message({
                    message: '编辑事项失败',
                    type: 'error'
                });
            })
        },
        clearData(){
            this.customerClassify ='',
            this.content = ''
        },
        toJump(){
            this.$router.replace({name:'attentionMatter'})
        }
    },
    created(){
        this.id = this.$route.query.id;
        this.getEditInfo(this.id)
        //console.log('获取传过来的Id',this.id)
    },
    watch:{
        $route:{
            handler(newVal,oldVal){
                //console.log('newVal',newVal.query.id)
                this.id = newVal.query.id;
                this.getEditInfo(newVal.query.id)
            }
        }
    }
}
</script>
<style scoped>
@import '../../../customerManagement/components/css/viewCommon.css';
.textArea {
    width: 100%;
    resize: none;
    border-radius: 5px;
    font-size: 14px;
    color: #606266;
    line-height: 1.5;
}
.formLayout {
    margin: 16px;
    background-color: #fff;
    height: 100%;
    overflow: auto;
    padding: 16px;
    border-radius: 8px;
}
</style>


